<template>
	<view class="beijingse mainpadding">
		<view class="mainpadding ffffff radius">
			<view class="ershib">转换类型</view>
			<view class="flexbetween xiahuax margin_top" v-if="valueType==0" @click="changetype(1)">
				<view class="noershib">积分</view>
				<!-- 已勾选 -->
				<view class="yigouxuan" v-if="type==1"></view>
				<!-- 未勾选 -->
				<view class="weigouxuan" v-if="type!=1"></view>
			</view>
			<view class="flexbetween xiahuax margin_top" v-if="valueType==1" @click="changetype(1)">
				<view class="noershib">奖金</view>
				<view class="yigouxuan" v-if="type==1"></view>
				<view class="weigouxuan" v-if="type!=1"></view>
			</view>
			<view class="flexbetween  margin_top" @click="changetype(2)">
				<view class="noershib">通证</view>
				<view class="yigouxuan" v-if="type==2"></view>
				<view class="weigouxuan " v-if="type!=2"></view>
			</view>
		</view>
		<view class="mainpadding ffffff radius margin_top">
			<view class="flexbetween">
				<view class="ershib">转换类型</view>
				<input class="huisetext textright" type="number" placeholder="请输入需要转换数量" v-model="num">
			</view>
		</view>
		<view class="mainpadding ffffff radius margin_top">
			<view class="flexbetween">
				<view class="ershib">可获得
				<text v-if="valueType==0 && type==1">积分</text>
				<text v-if="valueType==1 && type==1">奖金</text>
				<text v-if="type==2">通证</text>
				数</view>
				<view class="huangsetext">{{Number(num).toFixed(2)}}</view>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb" @click="submit">
			<view class="bigbtn">确认转换</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				valueType:0,//0奖金，1积分
				type:1,//1奖金、积分，2通证
				num:"",
			}
		},
		onLoad(options) {
			this.valueType = options.type
		},
		methods: {
			submit(){
				if(this.num=="" || this.num==0){
					httpRequest.toast("请输入转换数量")
					return
				}
				let data = {
					type:this.type,
					integral_price:this.num,
				}
				let url = ""
				if(this.valueType==0){
					data.bonus_price = data.integral_price
					delete data.integral_price
					url = "/api/user/zhBonusprice"
				}else{
					url = "/api/user/zhIntegralprice"
				}
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			changetype(value){
				this.type = value
			}
		}
	}
</script>

<style lang="scss" scoped>
	.xiahuax {
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.05);
	}

	.noershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.huangsetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FAB536;
	}

	.huisetext {
		width: 50%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}
</style>
